var tgd = tgd || {};
tgd.Simulations = tgd.Simulations || {};
tgd.Simulations.Zombies = tgd.Simulations.Zombies || {};

tgd.Simulations.Zombies.Person = function (physics, type, id) {

	var _p = physics;
	var _v;
	var _b;
	var _t = type;
	var _w;
	var _s = tgd.Simulations.Zombies.Enums.LifeState.Alive;
	var _i = id;

	var fov, ar, bt, wt;  //todo: abstract fov, ar
	
	switch (_t) {
		case tgd.Simulations.Zombies.Enums.HumanType.Civilian : fov = 50; ar = 0; bt = tgd.Simulations.Zombies.HumanBrain; wt = tgd.Simulations.Zombies.Enums.WeaponAction.Nothing; break;
		case tgd.Simulations.Zombies.Enums.HumanType.Hunter : fov = 50; ar = 20; bt = tgd.Simulations.Zombies.HunterBrain; wt = tgd.Simulations.Zombies.Enums.WeaponAction.Kill; break;
		case tgd.Simulations.Zombies.Enums.HumanType.Zombie : fov = 100; ar = 20; bt = tgd.Simulations.Zombies.ZombieBrain; wt = tgd.Simulations.Zombies.Enums.WeaponAction.Zombify; break;
		default : throw new Error("Type not specified correctly.");
	}

	_v = new tgd.Simulations.Zombies.Vision(_p, fov, _i)
	_b = new bt(_p, _v, _i);
	_w = new tgd.Simulations.Zombies.Weapon(_p, ar, wt, _i);

	//this.ID getter = function() { return _i; }
	//this.Vision getter = function() { return _v; }
	//this.Brain getter = function() { return _b; }
	//this.Attack getter = function() { return _w; }
	//this.Type setter = function(val) { _t = val; }
	//this.Type getter = function() { return _t; }
	//this.State getter = function() { return _s; }
	//this.State setter = function(val) { throw new Error("WHAT!"); }

	this.ID = _i;
	this.Vision = _v;
	this.Brain = _b;
	this.Attack = _w;
	this.Type = _t;
	this.State = _s;

	this.damage = function(w) {
		switch (w.ActionType) {
			case  tgd.Simulations.Zombies.Enums.WeaponAction.Nothing : break;
			case  tgd.Simulations.Zombies.Enums.WeaponAction.Kill : this.State = tgd.Simulations.Zombies.Enums.LifeState.Dead; break;
			case  tgd.Simulations.Zombies.Enums.WeaponAction.Zombify : {
				this.Type = tgd.Simulations.Zombies.Enums.HumanType.Zombie;
				this.Vision = new tgd.Simulations.Zombies.Vision(_p, 100, _i)
				this.Brain = new tgd.Simulations.Zombies.ZombieBrain(_p, this.Vision, _i);
				this.Attack = new tgd.Simulations.Zombies.Weapon(_p, 20, tgd.Simulations.Zombies.Enums.WeaponAction.Zombify, _i);
				break;
			}
			default : throw new Error("Invalid weapon action type.");
		}
	}

	this.heartBeat = function() {
		if (this.State === tgd.Simulations.Zombies.Enums.LifeState.Dead) { return; }
		var action = this.Brain.think();

		switch (action.Type) {
			case tgd.Simulations.Zombies.Enums.ActionType.Move : _p.move(this, action.Position); break;
			case tgd.Simulations.Zombies.Enums.ActionType.Attack : this.Attack.attack(action.Person); break;
			case tgd.Simulations.Zombies.Enums.ActionType.Nothing : break;
			default: throw new Error("TODO"); break;
		}
	}
}
